{include file="admin/common/header" /}
<body class="pear-container">
<div class="layui-form p-3">
    <div class="layui-form gg-form-bar border-x border-t">
        <h2>{$detail.title}</h2>
    </div>
    <table class="layui-table mb-2">
        <tr>
            <td class="layui-td-gray">文档数</td>
            <td style="width:50%">{$detail.count}</td>
            <td class="layui-td-gray">排序</td>
            <td>{$detail.sort}</td>
            <td class="layui-td-gray-2">是否首页显示</td>
            <td>
                {eq name="$detail.is_index" value="1"}是{/eq}
                {eq name="$detail.is_index" value="2"}否{/eq}
            </td>
            <td class="layui-td-gray" rowspan="3">封面图</td>
            <td rowspan="3" style="width:200px"><img src="{$detail.thumb}" style="max-width: 100%; height:100px;"/></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">知识库描述</td>
            <td colspan="5">{$detail.desc}</td>
        </tr>
        <tr>
            <td class="layui-td-gray" colspan="6" style="text-align:left;">
                <input type="hidden" name="book_id" value="{$detail.id}">
                <button class="layui-btn layui-btn-normal layui-btn-sm"
                        data-open="/app/book/admin/doc/add?book_id={$detail.id}" data-title="添加一级目录" data-reload="2">+ 添加一级目录
                </button>
                <button class="layui-btn layui-btn-primary layui-btn-sm close-doc">关闭</button>
            </td>
        </tr>
    </table>
    <table id="admin_table" lay-filter="admin_table"></table>
</div>

<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-zise pear-btn-xs" title="添加一级目录"
            data-open="/app/book/admin/doc/add?book_id={$detail.id}&pid={{d.id}}"
            data-title="添加一级目录" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-xs" title="编辑"
            data-open-full="/app/book/admin/doc/edit?id={{d.id}}"
            data-title="编辑" data-reload="2">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" title="删除"
            data-delete="/app/book/admin/doc/delete?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
</script>
{include file="admin/common/footer" /}
<script>
  layui.use(['table', 'jquery', 'treetable'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var treetable = layui.treetable;

    //关闭
    $('.close-doc').on('click', function () {
      if (parent.layui.admin) {
        parent.layui.admin.closeTab("book_doc_id_{$detail.id}");
      }
      return false;
    });

    treetable.render({
      toolbar: '#add_toolbar',
      treeColIndex: 4,
      treeSpid: 0,
      treeIdName: 'id',
      treePidName: 'pid',
      elem: '#admin_table',
      method: 'post',
      url: "/app/book/admin/doc/index",
      where:{book_id:'{$detail.id}'},
      page: false,
      cols: [[
        {field: 'id', width: 100, title: 'id', align: 'center'},
        {field: 'sort', width: 130, title: '排序', align: 'center'},
        {
          field: 'type', title: '类型', width: 80, align: 'center', templet: function (d) {
            var html = '';
            if (d.type == 1) {
              html = '文档';
            } else if (d.type == 2) {
              html = '分组';
            }
            if (d.type == 3) {
              html = '链接';
            }
            return html;
          }
        },
        {field: 'pid', width: 100, title: '父级ID', align: 'center'},
        {field: 'title', minWidth: 200, title: '章节名称'},
        {field: 'read', title: '查看', align: 'center', width: 80},
        {
          width: 200,
          title: '操作',
          templet: '#barDemo',
          align: 'center',
        }
      ]],
      done: function () {
        layer.closeAll('loading');
      }
    });

    table.on('toolbar(admin_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
